package com.SmartCare.controller.client;

import com.SmartCare.common.Result;
import com.SmartCare.common.note.Monitor;
import com.SmartCare.service.ActivityRecordService;
import com.SmartCare.service.ImageService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/activity")
@Api(tags = "C端娱乐活动记录")
@Slf4j
public class ActivityController {
    @Resource
    private ActivityRecordService activityRecordService;

    @Resource
    ImageService imageService;

    @Value("${files.upload.path}/activityImg/")
    private String fileUploadPath;

    @GetMapping("/add")
    public Result add(@RequestParam Long elderlyId,
                      Long nurseId,
                      String activityType,
                      Float duration,
                      @RequestParam(required = false) List<String> pictureUrls){
        return activityRecordService.add(elderlyId,nurseId,activityType,duration,pictureUrls);
    }

    /**
     * 查询老人固定日期的活动情况
     */
    @GetMapping("/info")
    @Monitor(description = "查询老人活动情况", module = "活动模块")
    public Result getInfo(Long elderlyId, String date){
        return activityRecordService.getInfo(elderlyId,date);
    }

    //添加活动图片
    @PostMapping("/upload")
    @Operation(summary = "上传图片文件", description = "将返回该图片的下载地址")
    public Result addImage(@RequestParam List<MultipartFile> file) {
        return imageService.upload(file, fileUploadPath, "activity");
    }

    //下载活动图片
    @GetMapping("/{fileUuid}")
    @Operation(summary = "下载图片文件", description = "直接访问该路径可下载图片")
    public void download(@PathVariable String fileUuid, HttpServletResponse response) throws IOException {
        imageService.download(fileUuid, fileUploadPath, response);
    }

}
